home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11477 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: solon.com!not-for-mail
  2. From: The Amorphous Mass <robinson@blue.weeg.uiowa.edu>
  3. Newsgroups: comp.lang.c,comp.lang.c.moderated
  4. Subject: Re: const pointer confusion...
  5. Date: 24 Mar 1996 11:42:20 -0600
  6. Organization: University of Iowa, Iowa City, IA, USA
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4j41hs$nku@solutions.solon.com>
  10. References: <4j06gm$7oa@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12. X-Sender: robinson@green.weeg.uiowa.edu
  13.  
  14. On 23 Mar 1996, Reed R. Mangino wrote:
  15.  
  16. > Could someone please straighten me out on this:
  17. > 1) const int *p = 10;
  18. >     p is a constant pointer to an int, right? While p can be made to
  19. >     point to something else, *p can never be assigned to, right?
  20.  
  21.   No, p is a pointer to a constant integer. However, you are right that 
  22. *p cannot change, but p can.
  23.  
  24. > 2) int *const p;
  25. >     p is a pointer to an integer.  *p can be assigned to, but p can
  26. >     never be made to point to another address in memory, right?
  27.  
  28.   This is a syntax error.
  29.  
  30. > 3) int const *p;
  31. >     What the heck is this?  I can't find anything like this in my 
  32. >     books, but my compiler thinks everything is hunky doory!???
  33.  
  34.   This is a constant pointer to an integer.  *p can be changed, but p 
  35. cannot.
  36.  
  37.   Also, there's
  38.  
  39.   4) const int const *p;
  40.  
  41.   Which is a constant pointer to a constant integer; neither *p nor 
  42. p can change.
  43.  
  44. /**James Robinson***********************            
  45.   "If a fatal error occurs, the program should not be allowed to continue."
  46.  -- Oracle Pro*C User's Guide         *************james-robinson@uiowa.edu**/
  47.